#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdlib.h>

int main()
{
  pid_t id=fork();
  if(id==0)
  {
    //child
    int cnt=5;
    while(cnt)
    {
      printf("child[%d] is running! cnt is %d\n",getpid(),cnt);
      cnt--;
      sleep(1);
    }
    exit(2);//退出码为2
  }
  int status=0;
  pid_t ret =waitpid(id,&status,0);
  if(ret>0)
  {
    printf("father wait:%d sucess,status wait code:%d,status exit signal:%d\n",ret,WEXITSTATUS(status),WIFEXITED(status));
  }
  else
  {
    printf("father wait failed!\n");
  }
  return 0;
}
